﻿using System;

namespace Mbs.Messaging
{
    /// <summary>
    /// 订阅者接口
    /// </summary>
    /// <typeparam name="TMessage">消息类型</typeparam>
    /// <remarks>采用设计模式中的观察者模式(发布者订阅者）模式，该接口担当了抽象订阅者角色</remarks>
    public interface ISubscriber<TMessage>
    {
        /// <summary>
        /// 主题名称
        /// </summary>
        string Name { get; set; }
        /// <summary>
        /// 订阅消息
        /// </summary>
        /// <param name="handler">消息处理器</param>
        /// <returns>返回一个可注销订阅者的对象</returns>
        IDisposable Subscribe(ObserverHandler<TMessage> handler);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="handler"></param>
        void Unsubscribe(ObserverHandler<TMessage> handler);

        IDisposable SubscribePreFilter(PreFilterHandler<TMessage> handler);
        void UnsubscribePreFilter(PreFilterHandler<TMessage> handler);

        IDisposable SubscribeFilter(FilterHandler<TMessage> handler);
        void UnsubscribeFilter(FilterHandler<TMessage> handler);

        IMessageListnerManager ListnerManager { get; set; }
        ObserverHandler<TMessage>[] Observers { get; }
        PreFilterHandler<TMessage>[] PreFilters { get; }
        FilterHandler<TMessage>[] Filters { get; }

        void ClearObservers();
        void ClearPreFilters();
        void ClearFilters();
        void ClearAll();
    }
    
}
